/**
 * @filename:OperLogController 2022-2-21
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2020 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.admin.controller;
import java.util.HashMap;
import java.util.Map;

import com.wonder.admin.domain.OperLog;
import com.wonder.admin.service.OperLogService;
import com.wonder.admin.request.OperLogRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;
import com.wonder.utils.DBUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**   
 * 
 * <p>说明： 操作日志API接口层</P>
 * @version: 1.1.0
 * @author: Wonder
 * @time    2022-2-21
 *
 */
@Api(tags = "操作日志")
@RestController
@RequestMapping("/admin/OperLog")
public class OperLogController {
	
	@Autowired
	private OperLogService operLogService;
	
	@Autowired
	private DBUtils dbUtils;
	@ApiOperation(value = "操作日志列表")
	@RequestMapping(value = "/index", method = RequestMethod.POST)
	public Map<String,Object> index(@RequestBody OperLogRequest operLogRequest) {
		Page<OperLog> page = new Page<OperLog>(operLogRequest.getPage(), operLogRequest.getLimit());
		IPage<OperLog> list = operLogService.selectList(operLogRequest, page);
		
		Map<String,Object> retMap=new HashMap<>();
		retMap.put("data",CommonPage.restPage(list));
		
        Map<String,Object> smallTable=new HashMap<>();
        smallTable.put("user_ids",dbUtils.getDropDownList("select user_id,name from sys_admin"));
        retMap.put("sql_field_data",smallTable);
  
		return AjaxMap.success(retMap);
	}
	
	/**
	 * @explain 获取sql语句定义的字段信息
	 * @param   对象参数：OperLog
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/getFieldList")
	@ApiOperation(value = "获取sql语句定义的字段信息", notes = "作者：Wonder")
	public AjaxResult<Map<String,Object>> getFieldList(){
	    Map<String,Object> smallTable=new HashMap<>();
        smallTable.put("user_ids",dbUtils.getDropDownList("select user_id,name from sys_admin"));
        return AjaxResult.success(smallTable);
	}
	
	/**
	 * @explain 修改单个字段值
	 * @param   对象参数：OperLog
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/updateExt")
	@ApiOperation(value = "修改单个字段值", notes = "作者：Wonder")
	public AjaxResult<OperLog> updateExt(@RequestBody OperLog entity){
		if (null!=entity) {
			boolean rsg = operLogService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	/**
	 * @explain 查看对象明细  
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@PostMapping("/detail")
	@ApiOperation(value = "获取操作日志对象明细", notes = "作者：Wonder")
	public AjaxResult<OperLog> detail(@RequestBody Map<String,Object> map){
	    if(map==null) AjaxResult.failed(MessageUtils.message("input.parameter.error"));
		Long oper_id=Long.parseLong(map.get("oper_id").toString());
	    
		OperLog operLog=operLogService.getById(oper_id);
		if (null!=operLog ) {
			 return AjaxResult.success(operLog);
		}else {
			 return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		}
		
	}
	
	
}